package com.itboye.ihomebank.adapter;

import java.util.List;
import java.util.Observable;
import java.util.Observer;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.bean.ChanKanWeiXiuBean;
import com.itboye.ihomebank.bean.ResultEntity;
import com.itboye.ihomebank.me.ActivityChaKanShiFu;
import com.itboye.ihomebank.presenter.RepairPersenter;
import com.itboye.ihomebank.support.commonadapter.MutiplyCommonAdapter;
import com.itboye.ihomebank.support.commonadapter.ViewHolder;
import com.itboye.ihomebank.util.ByAlert;
/**
 * 我的生活管家（维修中）
 *
 */
public class MyGuanJiaAdapter02 extends MutiplyCommonAdapter<ChanKanWeiXiuBean> implements Observer{
	List<ChanKanWeiXiuBean> datas;
	Context context;
	
	RepairPersenter repairPersenter;
	
	public MyGuanJiaAdapter02(Context context, List<ChanKanWeiXiuBean> datas,
			int... layoutId) {
		super(context, datas, layoutId);
		this.datas=datas;
		this.context=context;
	}

	@Override
	public int getItemViewType(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void getItemPosition(int position) {
		
	}

	@Override
	public void convert(ViewHolder holder, final ChanKanWeiXiuBean t, int type,
			int position) {
		holder.setText(R.id.guanjia_danhao, t.getId());
		holder.setText(R.id.guanjia_leixing, t.getRepairstatus());
		holder.setText(R.id.guanjia_address, t.getAddress());
		holder.setText(R.id.guanjia_name, t.getUname());
		
		holder.setText(R.id.guanjia_01, "查看师傅");
		holder.setText(R.id.guanjia_02, "修理完成");
		
		//查看师傅
		holder.setOnClickListener(R.id.guanjia_01, position, new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent=new Intent(context, ActivityChaKanShiFu.class);
				intent.putExtra("head", t.getHead());
				intent.putExtra("name", t.getWname());
				intent.putExtra("phone", t.getWmobile());
				intent.putExtra("id", t.getWid());
				context.startActivity(intent);
			}
		});
		//修理完成
		holder.setOnClickListener(R.id.guanjia_02, position, new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				repairPersenter=new RepairPersenter(MyGuanJiaAdapter02.this);
				repairPersenter.xiuLiEnd(t.getId());
			}
		});
		
	}

	@Override
	public void update(Observable observable, Object data) {
		ResultEntity entity = handlerError(data);
		// ByAlert.alert(entity.getData());
		if (entity != null) {
			if (!entity.getCode().equals(0)) {

				if (entity.getEventType() == RepairPersenter.theEnd_success) {
					ByAlert.alert(entity.getData());
					
				}
				if (entity.getEventType() == RepairPersenter.theEnd_fail) {
					ByAlert.alert(entity.getData());
				}
			}
		}
		
	}

}
